/**
 * 文件相关
 * @date: 2019-12-25

 */
import qs from 'query-string';
import { CPAAS_FILE } from "../config";
import { filterNullValueObject } from "./common";
import { getAccessToken } from "./token";
import { getCurrentOrganizationId, isTenantRoleLevel } from "./user";
/**
 * 通过文件服务器的接口获取可访问的文件URL
 *
 * @export
 * @param {String} url 上传接口返回的 Url
 * @param {String} bucketName 桶名
 * @param {Number} tenantId 租户Id
 * @param {String} bucketDirectory 文件目录
 * @param {String} storageCode 存储配置编码
 */
// @ts-ignore

export function getAttachmentUrl(url, bucketName, tenantId, bucketDirectory, storageCode) {
  var accessToken = getAccessToken();
  var params = qs.stringify(filterNullValueObject({
    bucketName: bucketName,
    storageCode: storageCode,
    access_token: accessToken,
    directory: bucketDirectory
  }));
  var newUrl = !isTenantRoleLevel() ? "".concat(CPAAS_FILE, "/v1/files/download?").concat(params, "&url=").concat(encodeURIComponent(url)) : "".concat(CPAAS_FILE, "/v1/").concat(getCurrentOrganizationId(), "/files/download?").concat(params, "&url=").concat(encodeURIComponent(url));
  return newUrl;
}